//
//  FaceType.m
//  ChampoinPeso
//
//  Created by mac on 2025/3/22.
//

#import "FaceType.h"

@interface FaceType ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong)UITableView *tableList;
@property(nonatomic, strong)NSString *sign;//A B;
@end

@implementation FaceType

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sign = @"A";
    [self setUI];
    // Do any additional setup after loading the view.
}


- (void)setUI {
    UIImageView *bgV = [[UIImageView alloc] initWithFrame:self.view.bounds];
    bgV.userInteractionEnabled = YES;
    bgV.image = [UIImage imageNamed:@"idtype_bg"];
    [self.view addSubview:bgV];
    self.navtitleText = @"ID Type";
    [self navUI];
    
    UIImageView *chooseV = [UIImageView new];
    chooseV.userInteractionEnabled = YES;
    chooseV.image = [UIImage imageNamed:@"idtype_sbg"];
    [bgV addSubview:chooseV];
    [chooseV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(STATUS_BAR_HEIGHT + 44 + 94);
        make.left.mas_equalTo(13);
        make.right.mas_equalTo(-13);
        make.height.mas_equalTo(400);
    }];
    
    UILabel *lab1 = [UILabel new];
    lab1.text = @"Recommended ID Type";
    lab1.textColor = [UIColor whiteColor];
    lab1.font = [UIFont systemFontOfSize:18];
    lab1.numberOfLines = 0;
    [chooseV addSubview:lab1];
    lab1.textAlignment = NSTextAlignmentCenter;
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(60);
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(0);
    }];
    
    UIView *lab1View = [UIView new];
    lab1View.backgroundColor = [UIColor whiteColor];
    [lab1 addSubview:lab1View];
    [lab1View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(4);
        make.centerX.equalTo(lab1);
        make.bottom.equalTo(lab1);
    }];
    lab1View.layer.cornerRadius = 2;
    lab1View.layer.masksToBounds = YES;
    
    UILabel *lab2 = [UILabel new];
    lab2.text = @"Other options";
    lab2.textColor = HexColor(@"#999999");
    lab2.font = [UIFont systemFontOfSize:18];
    lab2.numberOfLines = 0;
    [chooseV addSubview:lab2];
    lab2.textAlignment = NSTextAlignmentCenter;
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(60);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(0);
        make.width.equalTo(lab1);
        make.left.mas_equalTo(lab1.mas_right).offset(10);
    }];
    
    UIView *lab2View = [UIView new];
    lab2View.backgroundColor = [UIColor whiteColor];
    [lab2 addSubview:lab2View];
    [lab2View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(4);
        make.centerX.equalTo(lab2);
        make.bottom.equalTo(lab2);
    }];
    lab2View.layer.cornerRadius = 2;
    lab2View.layer.masksToBounds = YES;
    
    
    lab1View.hidden = NO;
    lab2View.hidden = YES;
    
    self.tableList = [[UITableView alloc] initWithFrame:CGRectZero];
    self.tableList.backgroundColor = UIColor.whiteColor;
    [chooseV addSubview:self.tableList];
    [self.tableList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab1.mas_bottom).mas_offset(14);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-14);
    }];
    self.tableList.delegate = self;
    self.tableList.dataSource = self;
    self.tableList.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableList.estimatedRowHeight = 40;
    self.tableList.showsVerticalScrollIndicator = NO;
    self.tableList.showsHorizontalScrollIndicator = NO;
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] init];
    lab1.userInteractionEnabled = YES;
    [lab1 addGestureRecognizer:tap1];
    [tap1 addActionBlock:^(id  _Nonnull sender) {
        lab1.textColor =  [UIColor whiteColor];
        lab2.textColor = HexColor(@"#999999");
        lab1View.hidden = NO;
        lab2View.hidden = YES;
        self.sign = @"A";
        [self.tableList reloadData];
    }];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] init];
    lab2.userInteractionEnabled = YES;
    [lab2 addGestureRecognizer:tap2];
    [tap2 addActionBlock:^(id  _Nonnull sender) {
        lab2.textColor =  [UIColor whiteColor];
        lab1.textColor = HexColor(@"#999999");
        lab2View.hidden = NO;
        lab1View.hidden = YES;
        self.sign = @"B";
        [self.tableList reloadData];
    }];
  
    
    
     
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
 
    NSString *tyoe = @"";
    if([self.sign isEqualToString:@"A"]){
        tyoe = self.typeA[indexPath.row];
        
    } else {
        tyoe = self.typeB[indexPath.row];
    }
    [[NSUserDefaults standardUserDefaults] setObject:tyoe forKey:@"typeCs"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self startMark:@"2"];
    [self.navigationController popViewControllerAnimated:NO];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if([self.sign isEqualToString:@"A"]){
        return self.typeA.count;
    } else {
        return self.typeB.count;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.contentView.backgroundColor = UIColor.whiteColor;
        UILabel *lab = [UILabel new];
        [cell.contentView addSubview:lab];
        lab.textColor = HexColor(@"#212121");
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(14);
            make.height.mas_equalTo(20);
            make.centerY.equalTo(cell.contentView);
        }];
        lab.font = [UIFont systemFontOfSize:16];
        lab.tag = 1001;
        
        UIView *lineV = [UIView new];
        lineV.backgroundColor = HexColor(@"#EFEFEF");
        [cell.contentView addSubview:lineV];
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(0);
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.height.mas_equalTo(1);
        }];
    }
    if([self.sign isEqualToString:@"A"]){
        ((UILabel *)[cell.contentView viewWithTag:1001]).text = self.typeA[indexPath.row];
    } else {
        ((UILabel *)[cell.contentView viewWithTag:1001]).text = self.typeB[indexPath.row];
    }
    return cell;
}
@end
